package com.htjc.integral.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 *  数据转换工具类
 * @author zw
 *
 */
public class DataConversionUtil {

	/**
	 * obj转map
	 * @param map
	 * @param beanClass
	 * @return
	 * @throws Exception
	 */
	public static Object mapToObject(Map<String, Object> map, Class<?> beanClass) throws Exception {    
		if (map == null)  
			return null;  

		Object obj = beanClass.newInstance();  

		org.apache.commons.beanutils.BeanUtils.populate(obj, map);  

		return obj;  
	}    
	/**
	 * map转obj
	 * @param obj
	 * @return
	 */
	public static Map<?, ?> objectToMap(Object obj) {  
		if(obj == null)  
			return null;   

		return new org.apache.commons.beanutils.BeanMap(obj);  
	}    
	/**
	 * 
	 * @param timestamp时间戳
	 * @param str 转换时间类型
	 * @return
	 * @throws ParseException
	 */
	public static Date  timestamptoDate(String timestamp,String str) throws ParseException {
		SimpleDateFormat format =  new SimpleDateFormat(str);  
		Long time=new Long(timestamp);  
		String d = format.format(time);  
		Date date=format.parse(d);  
		return date;
	}

}
